<?php

namespace App\Model;

use EasySwoole\ORM\AbstractModel;


class BaseModel extends AbstractModel
{
    /**
     * 新增检查结果
     * @throws \EasySwoole\ORM\Exception\Exception
     * @throws \Throwable
     */
    public function saveAndCheck()
    {
        $res = $this->save();
        if ($res === null) {
            throw new \Exception($this->lastQueryResult()->getLastError());
        }
    }

    /**
     * 更新检查结果
     * @param array $data
     * @param null $where
     * @param bool $allowUpdateWithNoCondition
     * @throws \EasySwoole\Mysqli\Exception\Exception
     * @throws \EasySwoole\ORM\Exception\Exception
     * @throws \Throwable
     */
    public function updateAndCheck(array $data = [], $where = null, $allowUpdateWithNoCondition = false)
    {
        $res = $this->update($data, $where, $allowUpdateWithNoCondition);
        if ($res === false) {
            throw new \Exception($this->lastQueryResult()->getLastError());
        }
    }
}
